//
//  JOAddViewController.m
//  私人通讯录
//
//  Created by song on 15/1/23.
//  Copyright (c) 2015年 song. All rights reserved.
//

#import "JOAddViewController.h"
#import "JOContects.h"
@interface JOAddViewController ()

@end

@implementation JOAddViewController

- (void)viewDidLoad {
    [super viewDidLoad];
   
    
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(textChange) name:UITextFieldTextDidChangeNotification object:self.nameField];
    
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(textChange) name:UITextFieldTextDidChangeNotification object:self.telField];

    // 让name 这个文本框成为第一响应者
//    [self.nameField resignFirstResponder];
    
}

/**
 *  控制器的view 完全显示的时候调用
 *
 *  @param animated <#animated description#>
 */
-(void)viewDidAppear:(BOOL)animated
{
    [self.nameField becomeFirstResponder];
}



- (void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

-(void)textChange
{
    if(self.nameField.text.length>0 && self.telField.text.length>0)
    {
        self.addbtn.enabled = YES;
    }else{
        self.addbtn.enabled =NO;
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



- (IBAction)addclick:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];
    
    if([self.delegate respondsToSelector:@selector(addViewController:withContects:)])
    {
        [self.delegate addViewController:self withContects:[JOContects contectsWithName:self.nameField.text andTel:self.telField.text]];
    }
    
}
@end
